package helper.base.math

import helper.base.math.TreeHelper.T2HierarchyStructure.Companion.makeT2ParentChildRelations
import org.junit.Test

internal class TreeHelperTest {
    @Test
    fun t_2023_0914_202113_() {
        val relations = makeT2ParentChildRelations<String>()

        // 使用辅助方法初始化层次关系
        relations.addRelations(null, listOf("sM1", "sM2", "sM3", "sM4"))
        relations.addRelations("sM1", listOf("sM10", "sM11", "sM12", "sM13"))
        relations.addRelations("sM2", listOf("sM20", "sM21", "sM22", "sM23"))
        relations.addRelations("sM3", listOf("sM30", "sM31", "sM32", "sM33"))
        relations.addRelations("sM4", listOf("sM40", "sM41", "sM42", "sM43"))

        // 测试查找功能
        println(relations.findChildren(null))  // 输出：[sM1, sM2, sM3, sM4]
        println(relations.findParent("sM10"))  // 输出：sM1

        println("relations=${relations}")
        val locations = arrayListOf("sM10", "sM20", "sM30", "sM40")
        val result = relations.findAllAncestors(locations)

        println("result=${result}")  // 输出所有激活位置的所有祖先节点
    }
}